<?php

class ArticleTagsModel extends Model{

	public $table = 'article_tags';
	//添加文章标签方法
	public function addData($aid){
		//没选文章标签，直接反出
		if(empty($_POST['tid'])) return true;
		foreach ($_POST['tid'] as $k => $t) {
			$data = array(
				'aid'	=> $aid,
				'tid'	=> $t,
				);
			$this->add($data);
		}
		return true;
	}

	public function getTid($aid=null){
		$aid = isset($aid) ? $aid : Q('aid',0,'intval');
		$where = array('aid'=>$aid);
		//getField('字段',true)  获取该字段将其压入一个数组中
		$tids = $this->where($where)->getField('tid',true);
		return $tids;
	}


	public function delByaid($aid=null){
		$aid = isset($aid) ? $aid : Q('aid',0,'intval');
		$where = array('aid'=>$aid);
		return $this->where($where)->delete();
	}

	public function editData($aid=null){
		$aid = isset($aid) ? $aid : Q('aid',0,'intval');
		// $re1 = $this->delByaid($aid);
		// $re2 = $this->addData($aid);
		// if($re1 and $re2){
		// 	return true;
		// }else{
		// 	return false;
		// }
		return $this->delByaid($aid) and $this->addData($aid);
	}
}

?>